package com.xxmw.transaction.conf;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ApplicationEventMulticaster;
import org.springframework.context.event.SimpleApplicationEventMulticaster;
import org.springframework.scheduling.concurrent.ThreadPoolExecutorFactoryBean;

/**
 * 币种聚合事件模式与线程池配置
 * @author xiangzuotao
 * @2020年5月25日
 */
@Configuration
public class SymbolAggregationConfig {

	@Bean
	public ApplicationEventMulticaster applicationEventMulticaster() {
		SimpleApplicationEventMulticaster sam = new SimpleApplicationEventMulticaster();
		sam.setTaskExecutor(symbolListnerThreadPool().getObject());
		return sam;
	}

	/**
	 * 币种事件监听线程池
	 * @return
	 */
	@Bean("symbolListnerThreadPool")
	public ThreadPoolExecutorFactoryBean symbolListnerThreadPool() {
		ThreadPoolExecutorFactoryBean tef = new ThreadPoolExecutorFactoryBean();
		tef.setCorePoolSize(3);
		tef.setMaxPoolSize(3);
		tef.setThreadNamePrefix("symbolListner-");
		return tef;
	}

	/**
	 * 币种业务线程池
	 * @return
	 */
	@Bean("symbolServiceThreadPool")
	public ThreadPoolExecutorFactoryBean symbolServiceThreadPool() {
		ThreadPoolExecutorFactoryBean tef = new ThreadPoolExecutorFactoryBean();
		tef.setCorePoolSize(20);
		tef.setMaxPoolSize(20);
		tef.setThreadNamePrefix("symbolService-");
		return tef;
	}
}
